package com.dzu.medium;

import com.dzu.common.ListNode;


/**
 * @author ZhaoDong
 * @date 2023/3/8 11:12
 * @description 24. 两两交换链表中的节点
 */
public class Test24 {

    public static ListNode swapPairs(ListNode head) {
        ListNode dummyHead = new ListNode();
        dummyHead.next = head;
        ListNode curr = dummyHead;

        while (curr.next != null && curr.next.next != null) {

            ListNode per = curr.next;
            ListNode next = per.next.next;

            curr.next = per.next;
            curr.next.next = per;
            per.next = next;

            curr = per;

        }
        return dummyHead.next;
    }
}
